Если во время итерации нужно получить доступ к соседним элементам, можно создать итератор, который сделает это автоматически.
from itertools import tee
def neighbours(iterable, n): neighbours = tee(iterable, n) for i, neighbour in enumerate(neighbours): for _ in range(i): next(neighbour)
return zip(*neighbours)
fibb = [1, 1, 2, 3, 5, 8, 13, 21]
for a, b, c in neighbours(fibb, 3): assert c == a + b
В этом примере мы разветвляем исходный итерируемый объект с помощью tee, затем сдвигаем полученные итераторы с помощью next, чтобы второй начинался со второго элемента исходного итерируемого объекта, а третий — с третьего, и затем объединяем их обратно с помощью zip.
Если во время итерации нужно получить доступ к соседним элементам, можно создать итератор, который сделает это автоматически.
from itertools import tee
def neighbours(iterable, n): neighbours = tee(iterable, n) for i, neighbour in enumerate(neighbours): for _ in range(i): next(neighbour)
return zip(*neighbours)
fibb = [1, 1, 2, 3, 5, 8, 13, 21]
for a, b, c in neighbours(fibb, 3): assert c == a + b
В этом примере мы разветвляем исходный итерируемый объект с помощью tee, затем сдвигаем полученные итераторы с помощью next, чтобы второй начинался со второго элемента исходного итерируемого объекта, а третий — с третьего, и затем объединяем их обратно с помощью zip.
That strategy is the acquisition of a value-priced company by a growth company. Using the growth company's higher-priced stock for the acquisition can produce outsized revenue and earnings growth. Even better is the use of cash, particularly in a growth period when financial aggressiveness is accepted and even positively viewed.he key public rationale behind this strategy is synergy - the 1+1=3 view. In many cases, synergy does occur and is valuable. However, in other cases, particularly as the strategy gains popularity, it doesn't. Joining two different organizations, workforces and cultures is a challenge. Simply putting two separate organizations together necessarily creates disruptions and conflicts that can undermine both operations.
Библиотека Python разработчика | Книги по питону from us